//
//  InformationViewController.m
//  YXFinance
//
//  Created by uplooking on 2018/10/22.
//  Copyright © 2018年 CRLong. All rights reserved.
//

#import "InformationViewController.h"

@interface InformationViewController ()
{
    
    FindMidChooseView * topView;
    NSInteger mTag;
    NSArray * arrayController;
    UIViewController *vcCurrent;
    
}

@end

@implementation InformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"资讯";
    mTag = 0;
    [self initView];
    [self initViewController];
    
}

- (void)initView{
    
    UIView * vTop = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 50 * kAutoScanleX)];
    [vTop setBackgroundColor:HexRGBA(0xeeeeee, 1)];
    [self.view addSubview:vTop];
    
    
    
    WS(weakSelf);
    topView=[[FindMidChooseView alloc]initWithFrame:CGRectMake(20 * kAutoScanleX, 0, kScreenWidth - 40 * kAutoScanleX, 50 * kAutoScanleX)];
    [topView setBackgroundColor:HexRGBA(0xeeeeee, 1)];
    topView.arrayTopTitle = @[@"活动视频",@"导师朋友圈",@"图文报道"];
    [topView setTextNormalColor:HexRGBA(0x2e2e2e, 1)];
    [topView setTextSelectedColor:HexRGBA(0xb99c6d, 1)];
    [topView setHkWidth:60 * kAutoScanleX];
    [topView setHkColor:HexRGBA(0xb99c6d, 1)];
    [vTop addSubview:topView];
    [topView setClickAction:^(NSInteger tag){
         [weakSelf setTopTag:tag];
    }];

    
}

- (void)initViewController{
    
    CGRect frame = CGRectMake(0, 50 * kAutoScanleX, kScreenWidth, kScreenHeight - NAVIGATION_BAR_HEIGHT - 50 * kAutoScanleX);
    
    ActiveVideoViewController * vc1 = [[ActiveVideoViewController alloc]init];
    vcCurrent = vc1;
    [vc1.view setFrame:frame];
    [self addChildViewController:vc1];
    [self.view addSubview:vc1.view];
    
    TutorViewController * vc2 = [[TutorViewController alloc]init];
    [vc2.view setFrame:frame];
    
    ImageTextViewController * vc3 = [[ImageTextViewController alloc]init];
    [vc3.view setFrame:frame];
    
    arrayController = @[vc1,vc2,vc3];
    
    
}

#pragma mark -- 资源
- (void)setTopTag:(NSInteger)tag{
    
    if (tag == mTag)
    {
        return;
    }
    
    NSInteger flagOld = mTag;
    mTag = tag;
    UIViewController * vcOld = arrayController[flagOld];
    UIViewController * vcNew = arrayController[mTag];
    [self replaceController:vcOld newController:vcNew];
    
}

//  切换各个标签内容
- (void)replaceController:(UIViewController *)oldController newController:(UIViewController *)newController
{
    [self addChildViewController:newController];
    [self transitionFromViewController:oldController toViewController:newController duration:0.15 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) {
        
        if (finished) {
            
            [newController didMoveToParentViewController:self];
            [oldController willMoveToParentViewController:nil];
            [oldController removeFromParentViewController];
            
            vcCurrent = newController;
            
        }else{
            
            vcCurrent = oldController;
            
        }
    }];
}



@end
